//
//  TextFieldTableViewCell.swift
//  SwiftProject
//
//  Created by qindong on 2021/8/9.
//  Copyright © 2021 qindong. All rights reserved.
//

import UIKit

class TextFieldTableViewCell: UITableViewCell {

    let titleLb : QMUILabel = QMUILabel()
    let detailTF : QMUITextField = QMUITextField()

    var model : CellModel! {
        didSet {
            titleLb.text = model.title.rawValue
            detailTF.text = model.detail
            detailTF.keyboardType = .default
            switch model.title {
            case .name:
                detailTF.placeholder = "请输入持卡人姓名"
                detailTF.keyboardType = .default
            case .cardNum:
                detailTF.placeholder = "请输入银行卡号"
                detailTF.keyboardType = .numberPad
            case .cardType:
                detailTF.placeholder = "请选择卡类型"
            default:
                break
            }

            if model.title == .cardType {
                accessoryType = .disclosureIndicator
                selectionStyle = .default
                detailTF.isEnabled = false
            } else {
                accessoryType = .none
                selectionStyle = .none
                detailTF.isEnabled = true
            }
        }
    }

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)

        titleLb.font = .rSFont(15)
        titleLb.textColor = .color51
        contentView.addSubview(titleLb)

        titleLb.snp.makeConstraints { make in
            make.left.equalTo(10)
            make.centerY.equalToSuperview()
            make.width.greaterThanOrEqualTo(77)
        }

        titleLb.setContentHuggingPriority(.required, for: .horizontal)

        detailTF.font = .rSFont(15)
        detailTF.placeholderColor = .color153
        detailTF.textColor = .color51
        contentView.addSubview(detailTF)

        detailTF.snp.makeConstraints { make in
            make.left.equalTo(titleLb.snp.right).offset(10)
            make.right.equalTo(-10)
            make.top.bottom.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
